<?php namespace App\Http\Controllers;

use App\Album as Album;
use App\Post as Upload;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Request;
use Illuminate\Support\Facades\Input;


class GalleryController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Home Controller
	|--------------------------------------------------------------------------
	|
	| This controller renders your application's "dashboard" for users that
	| are authenticated. Of course, you are free to change or remove the
	| controller as you wish. It is just here to get your app started!
	|
	*/

	/**
	 * Create a new controller instance.
	 *
	 * @return void
	 */


	/**
	 * Show the application dashboard to the user.
	 *
	 * @return Response
	 */
	public function index()
	{
		$albums = Album::all();
		return view('gallery.index', compact('albums'));
	}

	public function create()
	{
		return view('gallery.create');
	}

	public function storealbum()
	{
		$input = Request::all();
        $input['user_id'] ='1';

        Album::create($input);

        return redirect('gallery');
	}

	public function upload($album_id)
	{
		return view('gallery.upload', compact('album_id'));
	}

	public function storeupload($album_id)
	{
		$image = Input::file('image');
		$filename = $image->getClientOriginalName();
		Input::file('image')->move(public_path().'/images/', $filename);
		
        $upload = Request::all();
        $upload['image'] = $filename;
        $upload['album_id'] = $album_id;
        $upload['module_id'] = '2';
        $upload['user_id'] ='1';

        Upload::create($upload);

        return redirect('gallery');
	}

	public function album($album_id)
	{		
		$photos = Upload::where('album_id', $album_id)->get();
		return view('gallery.album', compact('photos', 'album_id'));
	}

}
